'''
Created on 2011-7-3

@author: JHL
'''
from cdsay.user.models import userModel
from django import newforms as forms
import time
from django.newforms.models import ModelForm

class loginForm(forms.Form):
    email = forms.CharField(max_length=30)
    password = forms.CharField(max_length=32)
    
    def clean_message(self):
        email=self.cleaned_data['email']
        num_words = len(email.split())
        if num_words < 1:
            raise forms.ValidationError("Please enter email!")
        password = self.cleaned_data['password']
        num_words = len(password.split())
        if num_words < 1:
            raise forms.ValidationError("Please enter password!")
        return forms

class registerForm(forms.Form):
    email = forms.CharField(max_length=30)
    password = forms.CharField(max_length=32)
    repassword = forms.CharField(max_length=32)
    
    def save(self):
        userModel.email=self.email
        userModel.password= self.password
        userModel.createtime = time.time()
        userModel.save(self)
        return self.email
    
class userForm(ModelForm):
    name = forms.CharField(max_length=30)
    password = forms.CharField(max_length=32)
    repassword = forms.CharField(max_length=32)
    class Meta:
        model = userModel